local options = {}
options["1"] = "select window-1"
options["2"] = "select window-2"
options["3"] = "select window-3"
options["4"] = "select window-4"
options["5"] = "select window-5"
options["6"] = "select window-6"
options["7"] = "select window-7"
options["8"] = "select window-8"
options["9"] = "select window-9"
options["10"] = "select window-10"

options.b = {
  name = "+buffer",
  -- b = { "<cmd>Buffers<cr>", "Buffer List" },
  q = { "<cmd>Bw<cr>", "remove all  buffers" },
  c = { "<cmd>Bonly<cr>", "keep current buffers" },
}

options.b.d = "Delete"

options.c = { name = "+code" }
options.c.f = "Format selected"
options.c.f = "Format selected code"
options.c.c = "Code  line Comment"
options.c.m = "Code  block Comment"
options.c.a = "Code Action"
options.c.e = "Code diagnostic"

options.d = { name = "+Debug" }
options.d.o = "Debug Repl"
options.d={
  R = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run to Cursor" },
  E = { "<cmd>lua require'dapui'.eval(vim.fn.input '[Expression] > ')<cr>", "Evaluate Input" },
  C = { "<cmd>lua require'dap'.set_breakpoint(vim.fn.input '[Condition] > ')<cr>", "Conditional Breakpoint" },
  U = { "<cmd>lua require'dapui'.toggle()<cr>", "Toggle UI" },
  -- b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
  c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
  d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
  e = { "<cmd>lua require'dapui'.eval()<cr>", "Evaluate" },
  g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
  h = { "<cmd>lua require'dap.ui.widgets'.hover()<cr>", "Hover Variables" },
  S = { "<cmd>lua require'dap.ui.widgets'.scopes()<cr>", "Scopes" },
  i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
  o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
  p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" },
  q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
  r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
  s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
  t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
  x = { "<cmd>lua require'dap'.terminate()<cr>", "Terminate" },
  u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
  b = { "<cmd>DapToggleBreakpoint<cr>", "set breakpoint" }
}

options.f = { name = "+find" }
options.f.a = "Find Word"
options.f.f = "Find File"
options.f.g = "Find files with git"
options.f.w = "Find current word"
options.f.h = "Find history"
options.f.m = "Find most used"
options.f.q = "Find quickfix"
options.f.r = "Find by farr"
options.f.s = "Find symbols"
options.f.t = "Find Tags"
options.f.W = "Find windows"
options.f.l = "Find Lines"
options.f.v = "Find visual text"
options.f.f = { "<cmd>Telescope find_files<cr>", "Find File" }
options.f.r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" }

options.h = {
  name = "+GitHunk" ,
  s="stage_hunk",
  r="reset_hunk",
  R="reset_buffer",
  d="diffthis",
  D="diffthis~",
}

options.g = {
  name = "+git",
  tl = "git lightlink",
  a = "git staged",
  p = "git preview",
  u = "git Unstage",
  r = "git Reset hunk",
  f = "git files",
  l = { "<cmd>GlLog<cr>", "git log" },
  g = { "<cmd>FloatermNew --height=0.9 --width=0.8 lazygit<cr>", "lazygit" },
  d = "diffthis",
  -- d = { "<cmd>Gvdiffsplit<cr>", "git diff" },
  s = "git status",
  c = { "<cmd>Git commit<cr>", "Git commit" },
}

options.i = "Vista"

options.o = { name = "+Open" }
options.o.c = "Open personal config"
options.o = "Symbol outline"

options.q = { name = "+quit" }
options.q.q = "Quit Buffer"
options.q.w = "Quit without save"

options.t = { name = "+toggle" }

options.s = { name = "+Selection" }
options.s.i = "Selection init"
options.s.n = "Selection increment"
options.s.N = "Selection decrement"
options.s.c = "Scope increment"
options.s.s = "SymbolsOutline"
options.s.t=  {'<cmd>lua require("spectre").toggle()<CR>', "Toggle Spectre"}
options.s.c={ '<cmd>lua require("spectre").open_visual({select_word=true})<CR>', "Search current word"}
-- options.s.c={'<esc><cmd>lua require("spectre").open_visual()<CR>', "Search current word"}
options.s.f={'<cmd>lua require("spectre").open_file_search({select_word=true})<CR>', "Search on current file"}


options.r = { name = "+Refactor" }
options.re = "+Refactor Variable"
options.rf = "+Refactor Function"
options.rff = "+Refactor Extract file"
options.rr = "+Refactor Extract()"

options.w = { name = "+Workspace" }
options.w.k = "Telescope workspace"
options.p = "Commands"

options.t = {
  name = "+terminal",
  f = { "<cmd>FloatermNew fzf<cr>", "fzf" },
  q = { "<cmd>FloatermKill<cr>", "quit" },
  g = { "<cmd>FloatermNew lazygit<cr>", "git" },
  d = { "<cmd>FloatermNew lazydocker<cr>", "docker" },
  n = { "<cmd>FloatermNew node<cr>", "node" },
  N = { "<cmd>FloatermNew nnn<cr>", "nnn" },
  p = { "<cmd>FloatermNew python<cr>", "python" },
  r = { "<cmd>FloatermNew ranger<cr>", "ranger" },
  t = { "<cmd>FloatermNew --wintype=popup --height=0.9 --width=0.9  zsh<cr>", "toggle" },
  y = { "<cmd>FloatermNew ytop<cr>", "ytop" },
  s = { "<cmd>FloatermNew ncdu<cr>", "ncdu" },
}
if vim.fn.has('win32') then
  options.t["t"] = { "<cmd>FloatermNew --wintype=popup --height=0.9 --width=0.9  cmd<cr>", "toggle" }
end

options.t[";"] = { "<cmd>FloatermNew --wintype=popup --height=6<cr>", "terminal" }
options.z = {
  name = "+Flods",
  O = {
    -- "<cmd>NvimTreeFocus<cr>",
    "<cmd>lua require('ufo').openAllFolds()<cr>",
    "openAllFolds",
  },
  C = {
    -- "<cmd>NvimTreeFocus<cr>",
    "<cmd>lua require('ufo').closeAllFolds()<cr>",
    "closeAllFolds",
  },
}
--[[options.x = {
  name = "+Explorer",
  f = {
    -- "<cmd>NvimTreeFocus<cr>",
    "<cmd>NvimTreeFindFileToggle<cr>",
    "find in nvimtree",
  },
}]]

local wk = require("which-key")
local mode = {
  mode = "n", -- NORMAL mode
  -- prefix: use "<leader>f" for example for mapping everything related to finding files
  -- the prefix is prepended to every mapping part of `mappings`
  prefix = "<leader>",
  buffer = nil,   -- Global mappings. Specify a buffer number for buffer local mappings
  silent = true,  -- use `silent` when creating keymaps
  noremap = true, -- use `noremap` when creating keymaps
  nowait = false, -- use `nowait` when creating keymaps
}
wk.register(options, mode)
